<?php
// +---------------------------------------------------------------
// | 公众号自动回复
// +---------------------------------------------------------------

declare(strict_types=1);

namespace app\api\logic;

class Official
{
    /**
     * 事件消息
     *
     * @param array $message 消息数据
     */
    public static function event(array $message)
    {
        $content = "温馨提示: \n\n您触发了事件消息推送\n\n微擎小程序TP6.0框架自动回复";
        if ($message['Event'] == 'subscribe' && !empty($message['EventKey'])) {
            // $message['EventKey'] 示例值: qrscene_1
            preg_match('/^qrscene_(\d+)$/', $message['EventKey'], $match);
            if (isset($match[1])) {
                $uid = $match[1];
                // 执行业务逻辑
                $content = "欢迎关注\n\n您的用户id为: " . $uid;
            }
        }
        return $content;
    }
}
